package com.hongxun.project.assets.kPdKg.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.kPdKg.domain.KPdKg;
import com.hongxun.project.assets.kPdKg.service.IKPdKgService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 配电-开关 信息操作处理
 * 
 * @author hongxun
 * @date 2019-06-25
 */
@Controller
@RequestMapping("/assets/kPdKg")
public class KPdKgController extends BaseController
{
    private String prefix = "assets/kPdKg";
	
	@Autowired
	private IKPdKgService kPdKgService;
	
//	@RequiresPermissions("assets:kPdKg:view")
	@GetMapping()
	public String kPdKg()
	{
	    return prefix + "/kPdKg";
	}


	@GetMapping("/choosekPdKg")
	public String choosekPdKg(KPdKg kPdKg , ModelMap modelMap)
	{
		modelMap.put("deviceId",kPdKg.getDeviceId());
		modelMap.put("pId",kPdKg.getPId());
		modelMap.put("byqId",kPdKg.getByqId());
		modelMap.put("taskStatus",kPdKg.getTaskStatus());

	    return prefix + "/choosekPdKg";
	}
	
	/**
	 * 查询配电-开关列表
	 */
//	@RequiresPermissions("assets:kPdKg:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(KPdKg kPdKg)
	{
		startPage();
        List<KPdKg> list = kPdKgService.selectKPdKgList(kPdKg);
		return getDataTable(list);
	}

	@PostMapping("/listChoosekPdKg")
	@ResponseBody
	public TableDataInfo listChoosekPdKg(KPdKg kPdKg)
	{

		startPage();
        List<KPdKg> list = kPdKgService.selectKPdKgList(kPdKg);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出配电-开关列表
	 */
	@RequiresPermissions("assets:kPdKg:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KPdKg kPdKg)
    {
    	List<KPdKg> list = kPdKgService.selectKPdKgList(kPdKg);
        ExcelUtil<KPdKg> util = new ExcelUtil<KPdKg>(KPdKg.class);
        return util.exportExcel(list, "kPdKg");
    }
	
	/**
	 * 新增配电-开关
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	@GetMapping("/addForDeviceId")
	public String addForDeviceId(KPdKg kPdKg , ModelMap modelMap)
	{
		modelMap.put("newByqId",kPdKg.getByqId());
		modelMap.put("newPointId",kPdKg.getPId());
		modelMap.put("newDeviceId",kPdKg.getDeviceId());
		return prefix + "/addForDeviceId";
	}

	/**
	 * 新增保存配电-开关
	 */
//	@RequiresPermissions("assets:kPdKg:add")
	@Log(title = "配电-开关", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(KPdKg kPdKg)
	{		
		return toAjax(kPdKgService.insertKPdKg(kPdKg));
	}

	/**
	 * 修改配电-开关
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		KPdKg kPdKg = kPdKgService.selectKPdKgById(id);
		mmap.put("kPdKg", kPdKg);
	    return prefix + "/edit";
	}

	//	修改低压配电柜
	@GetMapping("/editForDeviceId/{id}")
	public String editForDeviceId(@PathVariable("id") String id, ModelMap mmap)
	{
		KPdKg kPdKg = kPdKgService.selectKPdKgById(id);
		mmap.put("kPdKg", kPdKg);
	    return prefix + "/editForDeviceId";
	}
	
	/**
	 * 修改保存配电-开关
	 */
//	@RequiresPermissions("assets:kPdKg:edit")
	@Log(title = "配电-开关", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(KPdKg kPdKg)
	{		
		return toAjax(kPdKgService.updateKPdKg(kPdKg));
	}
	
	/**
	 * 删除配电-开关
	 */
//	@RequiresPermissions("assets:kPdKg:remove")
	@Log(title = "配电-开关", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(kPdKgService.deleteKPdKgByIds(ids));
	}
	
}
